package net.hhk.twitter;

import java.io.InputStream;
import java.net.URL;

import net.hhk.data.Constant;
import net.hhk.data.ThreadedRequest;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;

public class ViewImageActivity extends Activity {
	private String url_image;
	private ImageView image;
	private String local = "net.hhk.twitter.viewimage://";
	@Override
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//Bundle b = getIntent().getExtras();
		setContentView(R.layout.view_image);
		image= (ImageView)findViewById(R.id.tweet_image);
		Uri data = getIntent().getData();
		if (data != null) {
			String url = data.toString(); 
			url = url.trim();
			url_image = Constant.HOST+ url.substring(local.length());
			
		}
		final ThreadedRequest tReq = new ThreadedRequest();
		tReq.start(new Runnable() {
			public void run() {
				// This would stop whatever the other method
				// started
				// and let the user know
				 Object content = null;
				 try {
				 URL url = new URL(url_image);
				 content = url.getContent();
				 } catch (Exception ex) {
				 ex.printStackTrace();
				 }
				 InputStream is = (InputStream) content;
				 Drawable imagine = Drawable.createFromStream(is, "src");
				 // Image01.setImageDrawable(image);
				 image.setImageDrawable(imagine);
				
			}
		});
		
	}
}
